package com.youxue.teachin.set.main;

import java.util.List;

import com.library.uiframework.mvp.PagingDataLoadPresenter;
import com.library.uiframework.mvp.PagingDataLoadView;
import com.youxue.teachin.common.utils.DefaultSubscriber;
import com.youxue.teachin.common.vo.UserVO;
import com.youxue.teachin.set.main.maper.SetMaper;
import com.youxue.teachin.set.usercase.SetUserCase;
import com.youxue.teachin.user.userSystem.UserSystem;
import rx.Observable;

/**
 * 在此写用途
 *
 * @author: zhiwei
 * @date: 2017-10-05 21:41
 * @version: 9.1.0
 */
public class SetPresenter extends PagingDataLoadPresenter<PagingDataLoadView> {
    /**
     * @param pageDataLoadingView pageDataLoadingView
     */
    protected SetPresenter(PagingDataLoadView pageDataLoadingView) {
        super(pageDataLoadingView);
    }

    @Override
    protected void load(int page, boolean force) {
        UserVO userVO = UserSystem.getInstance().getUserVO();
        if (userVO == null) {
            Observable<List> observable = new SetUserCase().getUserInfoList();
            execute(observable, new DefaultSubscriber<List>() {
                @Override
                public void onError(Throwable e) {
                    super.onError(e);
                    List list = SetMaper.transformSet(null);
                    handleLoadSuccess(list, 1, 1);
                }

                @Override
                public void onNext(List list) {
                    super.onNext(list);
                    handleLoadSuccess(list, 1, 1);
                }
            });
        } else {
            List list = SetMaper.transformSet(userVO);
            handleLoadSuccess(list, 1, 1);
        }

    }
}
